package edu.nepu.flink.api.source;

import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

import java.util.Arrays;

/**
 * @Date 2024/2/28 9:10
 * @Created by chenshuaijun
 */
public class CollectionSource {

    public static void main(String[] args) throws Exception {

        // flink从1.13版本之后Source的使用从addSource转变成了fromSource

        // 下面使用集合创建Source

        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        // 设置并行度
        env.setParallelism(1);

        DataStreamSource<Integer> streamSource = env.fromCollection(Arrays.asList(1, 2, 3, 4, 5, 6));
//      使用这种方式也是可以的
//      DataStreamSource<Integer> streamSource = env.fromElements(1, 2, 3, 4, 5, 6);

        streamSource.print();

        env.execute();
    }
}
